package com.tastesport.chat.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tastesport.chat.model.redpacket.RedpacketGet;
import com.tastesport.chat.model.redpacket.RedpacketgetVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RedpacketGetMapper extends BaseMapper<RedpacketGet> {

    @Select("SELECT r.get_userid, FROM_UNIXTIME(r.get_time/1000,'%c月%d日 %H:%i') getTime, r.get_money, r.isbest,u.nickname getUserName,u.user_icon getUserIcon FROM chat_redpacket_get r INNER JOIN user u WHERE r.get_userid=u.id" +
            " AND r.redpacket_id = #{redpacketId} ORDER BY r.id")
    List<RedpacketgetVO> selectList(Integer redpacketId);

    @Select("SELECT * FROM (SELECT r.*,u.nickname getUserName,u.user_icon getUserIcon FROM chat_redpacket_get r INNER JOIN user u WHERE r.get_userid=u.id) t ${ew.customSqlSegment}")
    IPage<RedpacketgetVO> page(Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper);

}
